package com.dragon.mmochat.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;

public class MmochatKefuDao extends SimpleJdbcDaoSupport {
	private static final KefuRowMapper kefuMapper = new KefuRowMapper();

	// 获取未处理的玩家问题
	private static final String getkefuQuestionSql = "select * from kefu limit 1";

	public List<String> getkefuQuestion() {
		return getSimpleJdbcTemplate().query(getkefuQuestionSql, kefuMapper);
	}

	// 更新未处理的玩家问题
	private static final String saveKefuQuestionSql = "update kefu set question = ?";

	public void saveKefuQuestion(String question) {
		getSimpleJdbcTemplate().update(saveKefuQuestionSql, question);
	}

	// 新增一条空记录
	private static final String addNewKefuQuestionSql = "insert into kefu(question) values(?)";

	public void addNewKefuQuestion() {
		getSimpleJdbcTemplate().update(addNewKefuQuestionSql, "[]");
	}

	static class KefuRowMapper implements ParameterizedRowMapper<String> {
		@Override
		public String mapRow(ResultSet rs, int rowNum) throws SQLException {
			return rs.getString("question");
		}
	}
}